package com.example.feifei.net;

import java.util.HashMap;
import java.util.Map;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * 监听网络返回，并自己处理返回结果
 * Created by 陈飞飞 on 2018\6\29
 */

public class MySubscriber{

    ApiService service;

    public MySubscriber() {
        service =  RetrofitClient.getInstance().getApiService();
    }

    /**
     * 请求登陆易版本信息
     * @return
     */
    public Observable<String> getRxNetString(){
        Map<String,String> params = new HashMap<>();
        return observe(service.queryUrl(params).map(new Func1<String, String>() {
            @Override
            public String call(String s) {
                return s;
            }
        }));
    }

    /** * * @param observable * @param <T> * @return */
    private <T> Observable<T> observe(Observable<T> observable){
        return observable .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
}
